package com.project.oj.model.vo;

import cn.hutool.json.JSONUtil;
import com.google.gson.reflect.TypeToken;
import com.project.oj.model.dto.question.JudgeConfig;
import com.project.oj.model.entity.Question;
import lombok.Data;
import org.springframework.beans.BeanUtils;


import java.io.Serializable;
import java.util.Date;
import java.util.List;


@Data
public class QuestionVO implements Serializable {

    private Long id;


    private String title;


    private String content;


    private List<String> tags;


    private String answer;


    private Integer submitNum;


    private Integer acceptedNum;


    private JudgeConfig judgeConfig;


    private Integer thumbNum;


    private Integer favourNum;


    private Long userId;

    private Integer difficulty;

    private Date createTime;


    private Date updateTime;


    private UserVO userVO;



    public static Question voToObj(QuestionVO questionVO) {
        if (questionVO == null) {
            return null;
        }
        Question question = new Question();
        BeanUtils.copyProperties(questionVO, question);
        List<String> tagList = questionVO.getTags();
        if (tagList != null) {
            question.setTags(JSONUtil.toJsonStr(tagList));
        }
        JudgeConfig voJudgeConfig = questionVO.getJudgeConfig();
        if (voJudgeConfig != null) {
            question.setJudgeConfig(JSONUtil.toJsonStr(voJudgeConfig));
        }
        return question;
    }


    public static QuestionVO objToVo(Question question) {
        if (question == null) {
            return null;
        }
        QuestionVO questionVO = new QuestionVO();
        BeanUtils.copyProperties(question, questionVO);
        List<String> tagList = JSONUtil.toList(question.getTags(),String.class);
        questionVO.setTags(tagList);
        String judgeConfigStr = question.getJudgeConfig();
        questionVO.setJudgeConfig(JSONUtil.toBean(judgeConfigStr,JudgeConfig.class));
        return questionVO;
    }

    private static final long serialVersionUID = 1L;
}